package com.csyf.manager.schedule;

import com.csyf.manager.entity.SysAliAccount;
import com.csyf.manager.service.SysAliAccountBiz;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 每天晚上恢复额度
 * @Author: Enzo
 * @Date: 2018/10/26 19:13
 */
@Slf4j
public class RevertMoneySchedule  implements Job {

    @Autowired
    private SysAliAccountBiz sysAliAccountBiz;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("\n=================================\nRevertMoneySchedule\n===============================>>");

        log.info("scheduled : {}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

        log.info("----- 汇总未清算资金，更新用户余额账户-------");

        SysAliAccount sysAliAccount = new SysAliAccount();
        sysAliAccount.setChannelNo("alipay");
        List<SysAliAccount> querydata = sysAliAccountBiz.select(sysAliAccount);

        for (SysAliAccount querydatum : querydata) {
            sysAliAccountBiz.clearquota(querydatum.getId());
        }

        sysAliAccount.setChannelNo("alitran");
        List<SysAliAccount> querydata1 = sysAliAccountBiz.select(sysAliAccount);
        for (SysAliAccount querydatum : querydata1) {
            sysAliAccountBiz.clearquota(querydatum.getId());
        }

    }
}
